package org.lvws.hellospringcloud.helloalibaba.hellonacos.consumer.controller;

import org.lvws.hellospringcloud.helloalibaba.hellonacos.consumer.api.HelloNacosProviderApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.lang.management.ManagementFactory;

@RequestMapping("/nacos/consumer")
@RestController
public class HelloNacosConsumerController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private HelloNacosProviderApi helloNacosProviderApi;

    @GetMapping("/hello")
    public String hello() {
//        return restTemplate.getForObject("http://nacos-provider/nacos/provider/hello", String.class);
        return helloNacosProviderApi.hello() + " " + ManagementFactory.getRuntimeMXBean().getName();
    }

}
